package action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import entity.Admin;
import exception.ExamException;
import service.ExamService;
import service.impl.ExamServiceImpl;

/**
 * Created by honghao on 2017/2/20.
 */
public class AdminLoginAction extends ActionSupport implements ModelDriven<Admin>{
    private Admin admin = new Admin();
    private ExamService service = new ExamServiceImpl();
    public Admin getAdmin() {
        return admin;
    }

    public void setAdmin(Admin admin) {
        this.admin = admin;
    }

    @Override
    public Admin getModel() {
        return admin;
    }

    public String adminLogin() {
        try {
            boolean login = service.adminLogin(admin.getUsername(), admin.getPassword());
            if (login) {
                return SUCCESS;
            } else {
                return ERROR;
            }
        } catch (ExamException e) {
            e.printStackTrace();
            throw new RuntimeException("用户登陆失败！");
        }
    }
}
